package com.example.repository;

import com.example.model.entity.Post;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface PostRepository extends JpaRepository<Post, Long> {
    Page<Post> findByCategory(String category, Pageable pageable);
    Page<Post> findAll(Pageable pageable);

    List<Post> findByUserId(Long userId);

    Page<Post> findByUserId(Long userId, Pageable pageable);

    // 查询用户收藏的帖子
    @Query("SELECT p FROM Post p JOIN Collection c ON p.id = c.post.id WHERE c.user.id = :userId")
    Page<Post> findUserCollections(@Param("userId") Long userId, Pageable pageable);

    // 查询用户点赞的帖子
    //@Query("SELECT p FROM Post p JOIN Like l ON p.id = l.post.id WHERE l.user.id = :userId")
    //Page<Post> findUserLikedPosts(@Param("userId") Long userId, Pageable pageable);
} 